$(function (){
	$('#setcash').click(setCash);
	$('#setmin').click(setMin);
	$('#setmax').click(setMax);
	$('#btn_bet').click(doBet);
});

function setCash()
{
	var url = baseUrl + "/index.php?a=set";
	var data = {};
	data.cash = $("#cash").val();
	
	$.post(url, data, function (result){
		if (result.status == 0)
			alert(result.message);
	}, "json");
}

function setMin(){
	var url = baseUrl + "/index.php?a=set";
	var data = {};
	data.min = $("#min").val();
	
	$.post(url, data, function (result){
		if (result.status == 0)
			alert(result.message);
	}, "json");
}

function setMax(){
	var url = baseUrl + "/index.php?a=set";
	var data = {};
	data.max = $("#max").val();
	
	$.post(url, data, function (result){
		if (result.status == 0)
			alert(result.message);
	}, "json");
}

var betlock = false;
function doBet(){
	if (betlock)return;
	
	betlock = true;
	
	var url = baseUrl + "/index.php?a=dobet";
	var data = {};
	data.times = $('#times').val();
	for(var i=0; i< 8; i++){
		data['bet_' +i] = $('#bet_' + i).val();
	}
	
	var stat = {};
	
	$.post(url, data, function (result){
		betlock = false;
		
		if (result.status == 0)
			alert(result.message);
		else{
			$('#cash').val(result.cash+"");
			$('#min').val(result.min);
			$('#max').val(result.max);
			$('#bet_result').html(result.str);
		}
	}, "json");
}